package uml;

import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Font;
import java.awt.LayoutManager;
import java.awt.Panel;
import java.awt.TextArea;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;

import uml.controller.Controller;
import uml.util.listeners.DragListener;
import uml.view.ClassFormatter_View;
import uml.view.UMLContainerView;
import uml.view.factory.ContainerFactory;

class Driver
{
	public static final Color JTEXTAREA_BG_COLOR = Color.GRAY;
	public static final Color UMLCONTAINER_BG_COLOR = Color.GREEN;
	public static final Color WINDOW_BG_COLOR = Color.WHITE;
	public static final int TEXTAREACOUNT = 3;

	/**
	 * Main method - implements the model, view, and controller
	 * 
	 * @param args
	 */
	public static void main (String[] args)
	{
		Controller mainWindow = initWindow ();
		Container pane = mainWindow.getContentPane ();
		UMLContainerView umlContainer = initContainer ();
		UMLContainerView umlInterface = ContainerFactory.createInterfaceView ();
		UMLContainerView umlClass = ContainerFactory.createClassView ();
		pane.add (umlContainer);
		pane.add (umlInterface);
		pane.add (umlClass);
		ClassFormatter_View formatter = initFormatter ();
		formatter.setContainer (umlContainer);
		formatter.setFontBold ();
	}

	
	/**
	 * Creates the controller and sets up the main window layout and look.
	 * 
	 * @return Controller is returned with main window active.
	 */
	public static Controller initWindow ()
	{
		Controller mainWindow = new Controller ();
		Container pane = mainWindow.getContentPane ();
		pane.setBackground (WINDOW_BG_COLOR);
		pane.setLayout (new FlowLayout ());
		return mainWindow;
	}

	/**
	 * Initializes the formatter.
	 * 
	 * @return ClassFormatter_View
	 */
	public static ClassFormatter_View initFormatter ()
	{
		ClassFormatter_View formatter = new ClassFormatter_View ();
		return formatter;
	}

	/**
	 * Initializes UMLContainer and sets properties.
	 *
	 * @return UMLContainerView
	 */
	public static UMLContainerView initContainer ()
	{
		UMLContainerView container = new UMLContainerView ();
		container.setSize (100, 100);
		container.addDragListener (new DragListener (container));
		BoxLayout layout = new BoxLayout (container, BoxLayout.Y_AXIS);
		Border b = BorderFactory.createTitledBorder (BorderFactory.createEtchedBorder (), "test", TitledBorder.CENTER,
				TitledBorder.TOP);
		container.setBorder (b);
		container.setLayout (layout);
		container.setBackground (UMLCONTAINER_BG_COLOR);
		addJTextAreas (container);
		return container;
	}

	/**
	 * Takes a UMLContainerView and sets three JTextAreas in it. 
	 * Each will contain the string "Default Text".
	 * 
	 * @param container with JTextAreas added.
	 */
	public static void addJTextAreas (UMLContainerView container)
	{
		container.addFields (TEXTAREACOUNT);
	}
}